home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gzip124.gz / gzip124 / gzip-1.2.4 / gzexe.in (.txt) < prev    next >
Microsoft Windows Help File Content  |  1993-06-24  |  4KB  |  123 lines

  1. #!/bin/sh
  2. # gzexe: compressor for Unix executables.
  3. # Use this only for binaries that you do not use frequently.
  4. # The compressed version is a shell script which decompresses itself after
  5. # skipping $skip lines of shell commands.  We try invoking the compressed
  6. # executable with the original name (for programs looking at their name).
  7. # We also try to retain the original file permissions on the compressed file.
  8. # For safety reasons, gzexe will not create setuid or setgid shell scripts.
  9. # WARNING: the first line of this file must be either : or #!/bin/sh
  10. # The : is required for some old versions of csh.
  11. # On Ultrix, /bin/sh is too buggy, change the first line to: #!/bin/sh5
  12. x=`basename $0`
  13. if test $# = 0; then
  14.   echo compress executables. original file foo is renamed to foo~
  15.   echo usage: ${x} [-d] files...
  16.   echo   "   -d  decompress the executables"
  17.   exit 1
  18. tmp=gz$$
  19. trap "rm -f $tmp; exit 1" 1 2 3 5 10 13 15
  20. decomp=0
  21. res=0
  22. test "$x" = "ungzexe" && decomp=1
  23. if test "x$1" = "x-d"; then
  24.   decomp=1
  25.   shift
  26. echo hi > zfoo1$$
  27. echo hi > zfoo2$$
  28. if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; then
  29.   cpmod=${CPMOD-cpmod}
  30. rm -f zfoo[12]$$
  31. tail=""
  32. IFS="${IFS=     }"; saveifs="$IFS"; IFS="${IFS}:"
  33. for dir in $PATH; do
  34.   test -z "$dir" && dir=.
  35.   if test -f $dir/tail; then
  36.     tail="$dir/tail"
  37.     break
  38. IFS="$saveifs"
  39. if test -z "$tail"; then
  40.   echo cannot find tail
  41.   exit 1
  42. for i do
  43.   if test ! -f "$i" ; then
  44.     echo ${x}: $i not a file
  45.     res=1
  46.     continue
  47.   if test $decomp -eq 0; then
  48.     if sed -e 1d -e 2q "$i" | grep "^skip=[0-9]*$" >/dev/null; then
  49.       echo "${x}: $i is already gzexe'd"
  50.       continue
  51.     fi
  52.   if ls -l "$i" | grep '^...[sS]' > /dev/null; then
  53.     echo "${x}: $i has setuid permission, unchanged"
  54.     continue
  55.   if ls -l "$i" | grep '^......[sS]' > /dev/null; then
  56.     echo "${x}: $i has setgid permission, unchanged"
  57.     continue
  58.   case "`basename $i`" in
  59.   gzip | tail | chmod | ln | sleep | rm)
  60.     echo "${x}: $i would depend on itself"; continue ;;
  61.   esac
  62.   if test -z "$cpmod"; then
  63.     cp -p "$i" $tmp 2>/dev/null || cp "$i" $tmp
  64.     if test -w $tmp 2>/dev/null; then
  65.       writable=1
  66.     else
  67.       writable=0
  68.       chmod u+w $tmp 2>/dev/null
  69.     fi
  70.   if test $decomp -eq 0; then
  71.     sed 1q $0 > $tmp
  72.     sed "s|^if tail|if $tail|" >> $tmp <<'EOF'
  73. skip=18
  74. if tail +$skip $0 | "BINDIR"/gzip -cd > /tmp/gztmp$$; then
  75.   /bin/chmod 700 /tmp/gztmp$$
  76.   prog="`echo $0 | /bin/sed 's|^.*/||'`"
  77.   if /bin/ln /tmp/gztmp$$ "/tmp/$prog" 2>/dev/null; then
  78.     trap '/bin/rm -f /tmp/gztmp$$ "/tmp/$prog"; exit $res' 0
  79.     (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$ "/tmp/$prog") 2>/dev/null &
  80.     /tmp/"$prog" ${1+"$@"}; res=$?
  81.   else
  82.     trap '/bin/rm -f /tmp/gztmp$$; exit $res' 0
  83.     (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$) 2>/dev/null &
  84.     /tmp/gztmp$$ ${1+"$@"}; res=$?
  85.   echo Cannot decompress $0; exit 1
  86. fi; exit $res
  87.     "BINDIR"/gzip -cv9 "$i" >> $tmp || {
  88.       /bin/rm -f $tmp
  89.       echo ${x}: compression not possible for $i, file unchanged.
  90.       res=1
  91.       continue
  92.     }
  93.   else
  94.     # decompression
  95.     skip=18
  96.     if sed -e 1d -e 2q "$i" | grep "^skip=[0-9]*$" >/dev/null; then
  97.       eval `sed -e 1d -e 2q "$i"`
  98.     fi
  99.     if tail +$skip "$i" | "BINDIR"/gzip -cd > $tmp; then
  100.       :
  101.     else
  102.       echo ${x}: $i probably not in gzexe format, file unchanged.
  103.       res=1
  104.       continue
  105.     fi
  106.   rm -f "$i~"
  107.   mv "$i" "$i~" || {
  108.     echo ${x}: cannot backup $i as $i~
  109.     rm -f $tmp
  110.     res=1
  111.     continue
  112.   mv $tmp "$i" || cp -p $tmp "$i" 2>/dev/null || cp $tmp "$i" || {
  113.     echo ${x}: cannot create $i
  114.     rm -f $tmp
  115.     res=1
  116.     continue
  117.   rm -f $tmp
  118.   if test -n "$cpmod"; then
  119.     $cpmod "$i~" "$i" 2>/dev/null
  120.   elif test $writable -eq 0; then
  121.     chmod u-w $i 2>/dev/null
  122. exit $res
  123.